<?php
/**
 * Created by yusheng
 * Date: 2018/6/23
 * Time: 下午5:57
 */

namespace App\Observers;


use App\Models\Team;

class TeamObserver
{
    public function creating(Team $team)
    {
        $team->forceFill(['uuid' => $this->getUniqueUuid()]);
    }

    public function getUniqueUuid()
    {
        do {
            $uuid = str_random(10);
        } while (Team::query()->where('uuid', $uuid)->first() instanceof Team);

        return $uuid;
    }
}